package fourFragment.adapter;

import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.support.v4.graphics.drawable.DrawableCompat;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.xuegengwang.xuegengwang.R;

import java.util.ArrayList;

import common.BaseActivity;
import question.activity.QuestionDetail;
import fourFragment.bean.MyQuestionListBean;
import question.activity.VipQuestionDetail;
import utils.MyLogUtils;

/**
 * Created by Administrator on 2017/4/9.
 */

public class MyQuestionAdapter extends BaseAdapter {
    private Context context;
    private ArrayList<MyQuestionListBean.QuestionListBean> arrayList;
//    private onPraiseListener onPraiseListener;

    public MyQuestionAdapter(Context context, ArrayList<MyQuestionListBean.QuestionListBean> arrayList) {
        this.context = context;
        this.arrayList = arrayList;
//        this.onPraiseListener = onPraiseListener;
    }

    @Override
    public int getCount() {
        return arrayList.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        MyHolder myHolder;
        if (convertView == null) {
            myHolder = new MyHolder();
            convertView = LayoutInflater.from(context).inflate(R.layout.my_question_list_item, null);
            myHolder.my_question_list_item_tv = (TextView) convertView.findViewById(R.id.my_question_list_item_tv);
            myHolder.my_question_list_item_date = (TextView) convertView.findViewById(R.id.my_question_list_item_date);
//            myHolder.my_question_list_item_zanLayout = (LinearLayout) convertView.findViewById(R.id.my_question_list_item_zanLayout);
//            myHolder.my_question_list_item_zanIma = (ImageView) convertView.findViewById(R.id.my_question_list_item_zanIma);
//            myHolder.my_question_list_item_zan = (TextView) convertView.findViewById(R.id.my_question_list_item_zan);
//            myHolder.my_question_list_item_commentLayout = (LinearLayout) convertView.findViewById(R.id.my_question_list_item_commentLayout);
//            myHolder.my_question_list_item_commentIma = (ImageView) convertView.findViewById(R.id.my_question_list_item_commentIma);
//            myHolder.my_question_list_item_comment = (TextView) convertView.findViewById(R.id.my_question_list_item_comment);
            myHolder.my_question_list_item_cost = (TextView) convertView.findViewById(R.id.my_question_list_item_cost);
            myHolder.my_question_list_item_statue = (ImageView) convertView.findViewById(R.id.my_question_list_item_statue);
            convertView.setTag(myHolder);
        } else {
            myHolder = (MyHolder) convertView.getTag();
        }
        if ("free".equals(arrayList.get(position).getPrice())) {
            myHolder.my_question_list_item_cost.setVisibility(View.GONE);
        } else {
            myHolder.my_question_list_item_cost.setVisibility(View.VISIBLE);
        }

//        if(arrayList.get(position).getIs_prised()== 0){
//            //未点赞
//            myHolder.my_question_list_item_zanIma.setImageResource(R.mipmap.college_topic_item_zan_ima);
//        }else{
//            //已经点赞
//            myHolder.my_question_list_item_zanIma.setImageResource(R.mipmap.college_topic_item_zan_ima1);
//        }

        switch (arrayList.get(position).getState()) {
            case "未回复":
                myHolder.my_question_list_item_statue.setVisibility(View.VISIBLE);
                myHolder.my_question_list_item_statue.setImageResource(R.mipmap.unanswer_ima);
                break;
            case "未查看":
                myHolder.my_question_list_item_statue.setVisibility(View.VISIBLE);
                myHolder.my_question_list_item_statue.setImageResource(R.mipmap.uncheck_ima);
                break;
            case "未评价":
                myHolder.my_question_list_item_statue.setVisibility(View.VISIBLE);
                myHolder.my_question_list_item_statue.setImageResource(R.mipmap.uncomment_ima);
                break;
            case "正常":
            default:
                myHolder.my_question_list_item_statue.setVisibility(View.GONE);
                break;
        }
//        myHolder.my_question_list_item_zanLayout.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                onPraiseListener.praiseListener(position);
//            }
//        });

        convertView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                switch (arrayList.get(position).getPrice()) {
                    case "pay":
                        Intent i = new Intent();
                        if ("正常".equals(arrayList.get(position).getState())) {
                            i.setClass(context, QuestionDetail.class);
                        } else {
                            i.setClass(context, VipQuestionDetail.class);
                        }
                        i.putExtra("dialogId", arrayList.get(position).getDialogid());
                        i.putExtra("type", "my");
                        i.putExtra("state", arrayList.get(position).getState());
                        ((BaseActivity) context).startActivityForResult(i, position);
                        break;
                    case "free":
                    default:
                        Intent i1 = new Intent(context, QuestionDetail.class);
                        i1.putExtra("dialogId", arrayList.get(position).getDialogid());
                        i1.putExtra("type", "my");
                        i1.putExtra("state", arrayList.get(position).getState());
                        ((BaseActivity) context).startActivityForResult(i1, position);
                        break;
                }
            }
        });
        myHolder.my_question_list_item_tv.setText(arrayList.get(position).getQuestion());
        myHolder.my_question_list_item_date.setText(arrayList.get(position).getQuestion_time());
//        myHolder.my_question_list_item_zan.setText(arrayList.get(position).getPraise());
//        myHolder.my_question_list_item_comment.setText(arrayList.get(position).getComment());

        return convertView;
    }

    class MyHolder {
        ImageView my_question_list_item_statue;//问题状态
        TextView my_question_list_item_cost;//是否需要付费
        TextView my_question_list_item_tv;
        TextView my_question_list_item_date;
//        LinearLayout my_question_list_item_zanLayout;
//        ImageView my_question_list_item_zanIma;
//        TextView my_question_list_item_zan;
//        LinearLayout my_question_list_item_commentLayout;
//        ImageView my_question_list_item_commentIma;
//        TextView my_question_list_item_comment;
    }

//    public interface onPraiseListener {
//        void praiseListener(int position);
//    }
}
